package com.zqx.factory.utils;

import lombok.extern.slf4j.Slf4j;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.File;

/**
 * 解析xml文件工具类
 * @author zqx
 * @date 2018/09/01
 */
@Slf4j
public class XMLUtil {

    public static String getChartType()
    {

        try {
            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            Document doc = documentBuilder.parse(new File("src//main//java//com//zqx//factory//config//config.xml"));

            //获取包含图表类型的文本特点
            NodeList chartTypeNodeList = doc.getElementsByTagName("chartType");
            Node classNode = chartTypeNodeList.item(0).getFirstChild();
            String chartType = classNode.getNodeValue().trim();
            return chartType;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }

    public static void main(String[] args) {
        String chartType = getChartType();
        log.info("获取的值为："+chartType);
    }
}
